home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
tsoper
/
CT Explorer
/
Form1.cs
< prev
next >
Wrap
Text File
|
2005-05-08
|
5KB
|
231 lines
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CsGL.OpenGL;
namespace SampleGUI
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
///
public MainForm orthoForm;
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
orthoForm = new MainForm(this);
//this.MdiChildren = orthoForm;
//orthoForm.Show();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
public class MainForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
///
View view1 = new View();
View view2 = new View();
View view3 = new View();
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel3;
private System.ComponentModel.Container components = null;
public MainForm(Form parentForm)
{
//
// Required for Windows Form Designer support
//
//InitializeComponent();
//set the form to the parent form
this.Parent = parentForm;
//set the size of the window
//this.SetClientSizeCore(800,300);
//place the views in the panels
panel1 = new System.Windows.Forms.Panel();
this.panel1.Controls.AddRange(
new System.Windows.Forms.Control[] { this.view1 });
this.panel2 = new System.Windows.Forms.Panel();
this.panel2.Controls.AddRange(
new System.Windows.Forms.Control[] { this.view2 });
this.panel3 = new System.Windows.Forms.Panel();
this.panel3.Controls.AddRange(
new System.Windows.Forms.Control[] { this.view3 });
//add panel to form
this.Controls.AddRange(
new System.Windows.Forms.Control[] {this.panel1,
this.panel2,
this.panel3
});
int cx = this.ClientSize.Width;
int cy = this.ClientSize.Height;
//set position of panel and view docking and color
panel1.SetBounds(0,0,(int)(cx/3.0),cy);
panel1.BorderStyle = BorderStyle.Fixed3D;
view1.Dock = DockStyle.Fill;
view1.Color[0] = 1;
view1.Color[1] = 0;
view1.Color[2] = 0;
panel2.SetBounds((int)(cx/3.0),0,(int)(cx/3.0),cy);
panel2.BorderStyle = BorderStyle.Fixed3D;
view2.Dock = DockStyle.Fill;
view2.Color[0] = 0;
view2.Color[1] = 1;
view2.Color[2] = 0;
panel3.SetBounds((int)(2*cx/3.0),0,(int)(cx/3.0),cy);
panel3.BorderStyle = BorderStyle.Fixed3D;
view3.Dock = DockStyle.Fill;
view3.Color[0] = 0;
view3.Color[1] = 0;
view3.Color[2] = 1;
this.Resize += new EventHandler(form_Resize);
}
void form_Resize(object sender, EventArgs e)
{
int cx = this.ClientSize.Width;
int cy = this.ClientSize.Height;
//set position of panels
panel1.SetBounds(0,0,(int)(cx/3.0),cy);
panel2.SetBounds((int)(cx/3.0),0,(int)(cx/3.0),cy);
panel3.SetBounds((int)(2*cx/3.0),0,(int)(cx/3.0),cy);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
}
class View : OpenGLControl
{
public float[] Color = new float[3];
public View()
{
//default color to red
Color[0] = 1;
Color[1] = 0;
Color[2] = 0;
}
public override void glDraw()
{
GL.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT ); // Clear Screen And Depth Buffer
GL.glShadeModel( GL.GL_SMOOTH );
CsGL.OpenGL.GLUquadric q = GL.gluNewQuadric();
int radius;
radius = 1;
GL.gluQuadricDrawStyle(q,GL.GLU_LINE);
GL.glColor3fv(Color);
GL.gluSphere(q, radius, 20, 20);
GL.glFlush();
}
protected override void InitGLContext()
{
GL.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
GL.glEnable( GL.GL_DEPTH_TEST);
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
//GL.glOrtho( -20,20, -20,20, 0,1000);
GL.gluPerspective(90,1, 0.1,1000);
GL.glMatrixMode(GL.GL_MODELVIEW );
GL.glLoadIdentity();
GL.gluLookAt(0,0,3, 0,0,0, 0,1,0);
}
}
}